/**
 * Project Name:YCApiServer-Api
 * File Name:UserCenterService.java
 * Package Name:com.yc.music.service.service103
 * Date:2016年5月10日下午1:25:36
 * Copyright (c) 2016 
 *
 */
package com.yc.music.service.service21;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.yc.music.common.context.YcContext;
import com.yc.music.common.util.RoomUtil;
import com.yc.music.context.YtConstant;
import com.yc.music.mapper.cache.MusiciaWorkCacheMapper;
import com.yc.music.mapper.cache.MusicianCacheMapper;
import com.yc.music.model.musician.MusicMusician;
import com.yc.music.model.musician.MusicMusicianVo;
import com.yc.music.model.musicianwork.MusicMusicianWorkVo;

/**
 * 
 * ClassName: UserCenterService <br/>
 * Function: 音乐人相关. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2016年8月13日 下午2:32:17 <br/>
 *
 * @author qinhaiguan
 * @version
 */
@Service
public class MusicianService {

	@Value("${Pic_QiLiu}")
	private String pIC_QiLiu;
	
	@Value("${Audio_QiLiu}")
	private String Audio_QiLiu;
	
	@Value("${audio_buckname}")
	private String audio_buckname;
	
	@Value("${pic_buckname}")
	private String pic_buckname;
	
	@Autowired
	private MusicianCacheMapper musicianCacheMapper;
	
	@Autowired
	private MusiciaWorkCacheMapper musiciaWorkCacheMapper;
	
	/**
	 * 
	 * getMusicianList:获取音乐人列表. <br/> 
	
	 * @author qinhaiguan
	 * @param page  //页码数
	 * @param result
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public Map<String,Object> getMusicianList(Integer page,Map<String,Object> result) throws Exception {
		int rows=10;
		page=page==0?page=1:page;
		int start=(page-1)*rows;
		List<MusicMusicianVo> list = musicianCacheMapper.getMusicianList(start, rows);
		for (MusicMusicianVo musicMusicianVo : list) {
			musicMusicianVo.setPic(RoomUtil.jointDomain(musicMusicianVo.getPic(),pIC_QiLiu));
		}
		result.put(YcContext.CODE, 200);
		result.put(YcContext.MESSAGE, YcContext.EMPTY_STRING);
		result.put(YcContext.DATA, list);
		return result;
	}
	
	
	/**
	 * 
	 * getMusicianDetail:音乐人详情页. <br/> 
	 *
	 * @author panguixiang
	 * @param uid  //音乐人ID
	 * @param page //页码数
	 * @param result
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public Map<String,Object> getMusicianDetail(Integer uid,Integer page,Map<String,Object> result) throws Exception {
		Map<String,Object> dataMap = new HashMap<String,Object>();
		//计算分页
		int rows=10;
		page=page==0?page=1:page;
		int start=(page-1)*rows;
		
		MusicMusician musicMusician = musicianCacheMapper.getMusicianDetail(uid);
		if(musicMusician==null) {
			result.put(YcContext.CODE, 400);
			result.put(YcContext.MESSAGE, YtConstant.USER_IS_NOT_EXIST);
			result.put(YcContext.DATA, YcContext.EMPTY_STRING);
			return result;
		}
		
		//头像地址
		musicMusician.setPic(RoomUtil.jointDomain(musicMusician.getPic(),pIC_QiLiu));
		
		//第一页的时候放用户个人信息
		if (page==1) {
			dataMap.put("musician", musicMusician);
		}
		
		List<MusicMusicianWorkVo> list=musiciaWorkCacheMapper.getMusicianWorkList(uid,start, rows);
		for (MusicMusicianWorkVo musicMusicianWorkVo : list) {
			//封面地址
			musicMusicianWorkVo.setPic(RoomUtil.jointDomain(musicMusicianWorkVo.getPic(),pIC_QiLiu));
			//MP3地址
			musicMusicianWorkVo.setMp3(RoomUtil.jointDomain(musicMusicianWorkVo.getMp3(),Audio_QiLiu));
		}
		//音乐人作品列表
		dataMap.put("worklist", list);
		
		result.put(YcContext.CODE, 200);
		result.put(YcContext.MESSAGE, YcContext.EMPTY_STRING);
		result.put(YcContext.DATA, dataMap);
		return result;
	}
	
}
